package
{
	import starling.core.Starling;
	import starling.display.Image;
	import starling.display.MovieClip;
	import starling.display.Sprite;
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;

	public class TestSprite extends Sprite
	{
		private var img:Image;
		
		private var frame:int = 1;
		
		// Embed the Atlas XML
		[Embed(source="atlas.xml", mimeType="application/octet-stream")]
		public static const AtlasXml:Class;
		
		// Embed the Atlas Texture:
		[Embed(source="atlas.png")]
		public static const AtlasTexture:Class;
		
		public function TestSprite()
		{
			// create atlas
			var texture:Texture = Texture.fromBitmap(new AtlasTexture());
			var xml:XML = XML(new AtlasXml());
			var atlas:TextureAtlas = new TextureAtlas(texture, xml);
			
			// create movie clip
			var movie:MovieClip = new MovieClip(atlas.getTextures("flight_"), 10);
			movie.loop = true; // default: true
			addChild(movie);
			
			// control playback
			movie.play();
			Starling.juggler.add(movie);
		}
		
		public function changeTexture():void
		{
			var num:Number = (int)(Math.random() * 2 + 1);
			var name:String = "t" + num;
			img.texture = Root.assets.getTexture(name);
		}
		
		private function enterFrame():void
		{
			var name:String = "t" + frame;
			img.texture = Root.assets.getTexture(name);
			frame++;
			if(frame > 2)
			{
				frame = 1;
			}
		}
	}
}